import { CustomerEconomicInfo, IDictionaries, UserInfo } from "@/service/type";
import { View, Text, Textarea } from "@tarojs/components";
import { FC } from "react";
import { AtButton } from "taro-ui";
import Form, { Field, FormInstance, useForm } from "rc-field-form";
import { validateErrorHandler } from "@/utils/validate";
import styles from "./index.module.less";
import { Keys } from "../../useData";

interface IProps {
  form: FormInstance<UserInfo>;
  userInfo: Partial<UserInfo>;
  onSave: (data: Partial<UserInfo>) => void;
  onShowDrawerPanel: (name: Keys, type: IDictionaries) => void;
}

const Signature: FC<IProps> = ({ form, userInfo, onSave }) => {
  return (
    <View className={styles["signature-wrapper"]}>
      <Form
        form={form}
        component={View}
        onFinishFailed={validateErrorHandler}
        initialValues={{
          monologue: userInfo.monologue,
        }}
        onFinish={() => onSave(form.getFieldsValue())}
      >
        <View className={styles["title"]}>
          <Text className={styles["require"]}>*</Text>内心独白
        </View>
        <Field
          name="monologue"
          trigger="onInput"
          rules={[{ required: true, message: "请填写独白内容" }]}
        >
          <Textarea
            className={styles["textarea"]}
            placeholder="请输入"
          ></Textarea>
        </Field>
        <AtButton className={styles["btn"]} onClick={form.submit}>
          保存
        </AtButton>
      </Form>
    </View>
  );
};

export default Signature;
